package com.experiment05;

import com.experiment05.entity.College;
import com.experiment05.entity.Student;
import com.experiment05.entity.Teacher;
import com.experiment05.resource.DatabaseUtils;
import javax.swing.text.html.Option;
import java.util.List;
import java.util.Optional;

public class Test {
    public static void main(String[] args) {
        String college = getCollegeName(DatabaseUtils.STUDENTS.get(0));
        //System.out.println(college);
        isTeacher(DatabaseUtils.STUDENTS.get(0),"刘老师");
        //System.out.println(getCollegeName(DatabaseUtils.STUDENTS,202121));
        printCollegeName(DatabaseUtils.STUDENTS,202121,0001);
    }
    private static String getCollegeName(Student student) {
        String college = Optional.ofNullable(student)
                .map(Student::getTeacher)
                .map(Teacher::getCollege)
                .map(College::getName)
                .orElse("未知学院");
        return college;

    }
    private static void isTeacher(Student student, String teacherName) {
        Optional.ofNullable(student)
                .map(Student::getTeacher)
                .filter(s -> s.getName().equals(teacherName))
                .ifPresentOrElse(s -> System.out.println("true"), () ->System.out.println("false"));
    }
    private static String getCollegeName(List<Student> students, int sNumber) {
      return students.stream()
              .filter(student -> student.getNumber() == sNumber)
              .findFirst()
              .map(Test::getCollegeName)
              .orElse("未知学院");




    }
    private static void printCollegeName(List<Student> students, int sNumber, int tNumber) {
     String college =students.stream()
                .filter(student -> student.getNumber() == sNumber)
                .filter(student -> student.getTeacher().getNumber() == tNumber)
                .findFirst()
                .map(Test::getCollegeName)
                .orElse("未知学院");
        System.out.println(college);
    }
}
